#include "drawmoney.h"
#include "ui_drawmoney.h"
#include "ClientSocket.h"
#include "vector_serialization.h"
#include<iostream>
#include "getcurrent.h"
#include<QMessageBox>
drawmoney::drawmoney(QWidget *parent, std::string name) :
        QWidget(parent),workername(name),
        ui(new Ui::drawmoney)
{
        ui->setupUi(this);
        ui->label_workername->setText(QString::fromStdString("工作人员:" + name));
        connect(ui->pushButton_submit, SIGNAL(clicked()),
                this, SLOT(handleSubmit()));

}

drawmoney::~drawmoney()
{
        delete ui;
}

void drawmoney::handleSubmit() {
        std::string sendmsg, reply;
        std::string cid, uname, odmoney, oddate;
        cid = ui->lineEdit_cid->text().toStdString();
        uname = workername;
        odmoney = ui->lineEdit_money->text().toStdString();
        time_t t1 = time(NULL);
        gettime(t1, oddate);
        ClientSocket client_socket("localhost",30000);
        map<std::string, std::string> smap;
        smap["code"] = "006";
        smap["oddate"] = oddate;
        smap["uname"] = uname;
        smap["cid"] = cid;
        smap["odmoney"] = odmoney;
        sendmsg = save(smap);
        client_socket << sendmsg;
        client_socket >> reply;
        std::cout << "reply:" << reply << std::endl;
        QMessageBox::about(0,"reply:",QString::fromStdString(reply));
}
